package com.kssoft.ebd.service.impl;


import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kssoft.ebd.dto.req.*;
import com.kssoft.ebd.dto.rest.CallRecordResponseDTO;
import com.kssoft.ebd.dto.rest.IssueLiveStreamDTO;
import com.kssoft.ebd.dto.rest.StartCallDTO;
import com.kssoft.ebd.service.ApiBroadcastService;
import com.kssoft.ebd.spider.common.config.CallRecordListQueryParamConfig;
import com.kssoft.ebd.spider.common.config.IssueLiveStreamParamConfig;
import com.kssoft.ebd.spider.common.config.SpiderConfig;
import com.kssoft.ebd.spider.common.config.StartCallParamConfig;
import com.kssoft.ebd.spider.http.HttpClientUtil;
import com.kssoft.ebd.spider.processor.CloseBroadcastProcessor;
import com.kssoft.ebd.spider.processor.StartBroadcastProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class ApiBroadcastImpl implements ApiBroadcastService {


    @Autowired
    private SpiderConfig spiderConfig;
    @Autowired
    private IssueLiveStreamParamConfig issueLiveStreamParamConfig;
    @Autowired
    private StartCallParamConfig startCallParamConfig;
    @Autowired
    private CallRecordListQueryParamConfig callRecordsQueryParamConfig;

    @Autowired
    private StartBroadcastProcessor startBroadcastProcessor;
    @Autowired
    private CloseBroadcastProcessor closeBroadcastProcessor;

    private SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");


    private ObjectMapper objectMapper = new ObjectMapper();

    /**
     * 已开启语音广播记录ID
     */
    public static Set<String> ebSpeakerCallIdList = new HashSet<>();

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    /**
     *  查询区域设备
     * @param areaDeviceQueryParamDTO
     * @return
     */
    @Override
    public String queryAreaDevice(AreaDeviceQueryParamDTO areaDeviceQueryParamDTO) {
        if(areaDeviceQueryParamDTO == null) {
            areaDeviceQueryParamDTO = new AreaDeviceQueryParamDTO();
            areaDeviceQueryParamDTO.setDivision("5105030101");
            areaDeviceQueryParamDTO.setShow_stb_t("true");
            areaDeviceQueryParamDTO.setShow_ip_t("true");
            areaDeviceQueryParamDTO.setAddSelf("false");
            areaDeviceQueryParamDTO.setShow_rds_t("false");
            areaDeviceQueryParamDTO.setShow_integratedDevice_t("false");
        }else {
            if(areaDeviceQueryParamDTO.getDivision() == null){
                areaDeviceQueryParamDTO.setDivision("5105030000");
            }
            if(areaDeviceQueryParamDTO.getAddSelf() == null){
                areaDeviceQueryParamDTO.setAddSelf("true");
            }
            if(areaDeviceQueryParamDTO.getShow_stb_t() == null){
                areaDeviceQueryParamDTO.setShow_stb_t("true");
            }
            if(areaDeviceQueryParamDTO.getShow_ip_t() == null){
                areaDeviceQueryParamDTO.setShow_ip_t("true");
            }
            if(areaDeviceQueryParamDTO.getShow_rds_t() == null){
                areaDeviceQueryParamDTO.setShow_rds_t("false");
            }
            if(areaDeviceQueryParamDTO.getShow_integratedDevice_t() == null){
                areaDeviceQueryParamDTO.setShow_integratedDevice_t("false");
            }
        }
        Map<String, String> paramMap = objectMapper.convertValue(areaDeviceQueryParamDTO, Map.class);

        //获取开播 Cookie
        Map<String, String> startBroadcastCookies =   startBroadcastProcessor.getStartBroadcastCookies();
        try {
            String result = HttpClientUtil.doGet(spiderConfig.getQueryAreaDeviceUrl(), paramMap, startBroadcastCookies, null);
            return result;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     *   查询开播状态列表
     * @param date
     * @param runningType
     * @param scheduleId
     * @return
     */
    @Override
    public String queryDayScheduleAction(String date, String runningType, String scheduleId) {

        try {
            //获取开播 Cookie
            Map<String, String> startBroadcastCookies = startBroadcastProcessor.getStartBroadcastCookies();
            Map<String, String> params = new HashMap<>();
            //2025-06-10 日期格式  今日
            if(date != null && !date.isEmpty()){
                params.put("date", date);
            }else{
                Date now = new Date();
                params.put("date", simpleDateFormat.format(now));
            }
             if(runningType != null && !runningType.isEmpty()){
                params.put("runningType", runningType);
            }else {
                params.put("runningType", "1");
            }
             if(scheduleId != null && !scheduleId.isEmpty()){
                params.put("scheduleId", scheduleId);
            }else {
                params.put("scheduleId", "");
            }
            String result = HttpClientUtil.doGet(spiderConfig.getQueryDayScheduleActionUrl(), params, startBroadcastCookies, null);
            return result;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

        /**
     * 查询音频文件列表
     *  ED_STREAM-查询网络直播流列表
     *  ED_FILE-查询文件资源列表
     * @param audioFileQueryParamDTO
     * @return
     */
    @Override
    public String queryAudioFile(AudioFileQueryParamDTO audioFileQueryParamDTO) {
        //获取开播 Cookie
        Map<String, String> startBroadcastCookies = startBroadcastProcessor.getStartBroadcastCookies();
        try {
            audioFileQueryParamDTO.setQueryCaptureType("ED_FILE");


            Map<String, String> paramMap = objectMapper.convertValue(audioFileQueryParamDTO, Map.class);

            String result = HttpClientUtil.doPost(spiderConfig.getQueryAudioFileUrl(), paramMap, startBroadcastCookies, null);
            return result;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     *  查询音频流资源列表
     * @param audioFileQueryParamDTO
     * @return
     */
    @Override
    public String queryAudioStream(AudioFileQueryParamDTO audioFileQueryParamDTO) {
        //获取开播 Cookie
        Map<String, String> startBroadcastCookies = startBroadcastProcessor.getStartBroadcastCookies();
        try {
            audioFileQueryParamDTO.setQueryCaptureType("ED_STREAM");
            Map<String, String> paramMap = objectMapper.convertValue(audioFileQueryParamDTO, Map.class);
            String result = HttpClientUtil.doPostJson(spiderConfig.getQueryAudioFileUrl(), JSON.toJSONString(paramMap), startBroadcastCookies, null);
            return result;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * 查询关播播放列表状态
     * @param callRecordQueryListParam
     * @return
     */
    @Override
    public String queryCallRecordAjax(CallRecordQueryListParamDTO callRecordQueryListParam) {
        if(callRecordQueryListParam == null){
            callRecordQueryListParam = new CallRecordQueryListParamDTO();
            callRecordQueryListParam.setPageNum("1");
            callRecordQueryListParam.setPageSize("10");
            callRecordQueryListParam.setWriteLogFlag("0");
            callRecordQueryListParam.setConditionUser("");
            callRecordQueryListParam.setConditionStartTime("");
            callRecordQueryListParam.setContiditonType("17");
            callRecordQueryListParam.setDeviceIndentify("");

        }
        if(callRecordQueryListParam.getPageNum() == null){
            callRecordQueryListParam.setPageNum("1");
        }
        if(callRecordQueryListParam.getPageSize() == null){
            callRecordQueryListParam.setPageSize("10");
        }
        if(callRecordQueryListParam.getWriteLogFlag() == null){
            callRecordQueryListParam.setWriteLogFlag("0");
        }
        if(callRecordQueryListParam.getContiditonType() == null){
            callRecordQueryListParam.setContiditonType("-1");
        }

        // 获取关播主页cookie
        Map<String, String> closeBroadcastCookies = closeBroadcastProcessor.getCloseBroadcastCookies();
        try {
            Map<String, String> paramMap = objectMapper.convertValue(callRecordQueryListParam, Map.class);
            String s = HttpClientUtil.doPost(spiderConfig.getQueryCallRecordAjaxUrl(),paramMap, closeBroadcastCookies, null);
            return s;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * 开播-直播流
     * @param issueLiveStreamParamDTO
     * @return
     */
    @Override
    public IssueLiveStreamDTO issueLiveStream(IssueLiveStreamParamDTO issueLiveStreamParamDTO) {

        String jsonParamString = getJsonParamString(issueLiveStreamParamDTO);
        //获取开播 Cookie
        Map<String, String> startBroadcastCookies = startBroadcastProcessor.getStartBroadcastCookies();
        try {
            Map<String, String> paramMap = objectMapper.readValue(jsonParamString, Map.class);
            String result = HttpClientUtil.doPost(spiderConfig.getIssueLiveStreamUrl(),paramMap , startBroadcastCookies, null);
            // 测试数据
//            String result= "{\n" +
//                    "    \"areaListString\": \"5105030101\",\n" +
//                    "    \"assetName\": \"æ³¸å\u008E¿å¹¿æ\u0092\u00AD(udp://@192.168.19.182:35004)\",\n" +
//                    "    \"audioFileType\": null,\n" +
//                    "    \"broadCastType\": 0,\n" +
//                    "    \"callRecordId\": null,\n" +
//                    "    \"errMsg\": null,\n" +
//                    "    \"fileId\": 28,\n" +
//                    "    \"issueTerminals\": \"\",\n" +
//                    "    \"mediaType\": \"audio\",\n" +
//                    "    \"programId\": null,\n" +
//                    "    \"resultString\": \"startCut\",\n" +
//                    "    \"schemeType\": -1,\n" +
//                    "    \"volume\": 80\n" +
//                    "}";
            logger.info("开播结果：{}", result);
            IssueLiveStreamDTO issueLiveStreamDTO = JSON.parseObject(result, IssueLiveStreamDTO.class);
            if(issueLiveStreamDTO != null) {

                String resultString = issueLiveStreamDTO.getResultString();
                if (issueLiveStreamDTO.getErrMsg() == null || issueLiveStreamDTO.getErrMsg().isEmpty()) {
                    if ("startCut".equals(issueLiveStreamDTO.getResultString())) {
                        if ("2".equals(issueLiveStreamDTO.getSchemeType())) {
                            //RDS
                            resultString = "存在更高级别的广播";
                        } else {
                            resultString = "下发成功，存在更高级别的广播";
                        }
                    } else if ("chnlError".equals(issueLiveStreamDTO.getResultString())) {
                        resultString = "无空闲下发通道";
                    } else {
                        resultString = "下发完成";
                    }
                    logger.info("开播结果：{}", resultString);
                } else {
                    logger.info("开播结果：{}", issueLiveStreamDTO.getErrMsg());
                }
                issueLiveStreamDTO.setResultString(resultString);


                logger.info("开播CallRecordId：{}", issueLiveStreamDTO.getCallRecordId());
            }
            return issueLiveStreamDTO;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    /**
     *  根据播放区域查询开播 CallRecordId
     * @return
     */
    @Override
    public String findPlayingBroadcastCallRecordId(String xydTargetAreaCodeList) {

        try {

            List<CallRecordResponseDTO.CallRecord> callRecordList = getStartBroadcastCallRecords();

            if (callRecordList != null && !callRecordList.isEmpty()){
                for (int i = 0; i < callRecordList.size(); i++) {
                    CallRecordResponseDTO.CallRecord callRecord = callRecordList.get(i);
                    if (callRecord.getStatus() == 0 // 0:广播进行中 1:已停止
                            && callRecordsQueryParamConfig.getCallerName().equals(callRecord.getCallerName())
                            && callRecordsQueryParamConfig.getAssetName().equals(callRecord.getAssetName())
                            && callRecord.getType() == Integer.parseInt(callRecordsQueryParamConfig.getType())
                    && checkAreaCode(xydTargetAreaCodeList, callRecord.getTargetAreaList())) {
                        return String.valueOf(callRecord.getId());
                    }
                }
            }

        } catch (Exception e) {
            logger.error("查找区域开播记录异常");
            e.printStackTrace();
            throw new RuntimeException(e);
        }
        return null;
    }

    /**
     *  查询直播流前100条开播记录
     * @return
     * @throws Exception
     */
    private List<CallRecordResponseDTO.CallRecord> getStartBroadcastCallRecords() throws Exception {

        // 获取关播主页cookie
        Map<String, String> closeBroadcastCookies = closeBroadcastProcessor.getCloseBroadcastCookies();
        CallRecordQueryListParamDTO    callRecordQueryListParam = new CallRecordQueryListParamDTO();
        callRecordQueryListParam.setPageNum("1");
        callRecordQueryListParam.setPageSize("100");
        callRecordQueryListParam.setWriteLogFlag("0");
        callRecordQueryListParam.setConditionUser("");
        callRecordQueryListParam.setConditionStartTime("");
        callRecordQueryListParam.setContiditonType("-1");
        callRecordQueryListParam.setDeviceIndentify("");
        if(callRecordsQueryParamConfig.getConditionUser() != null && !callRecordsQueryParamConfig.getConditionUser().isEmpty()){
            callRecordQueryListParam.setConditionUser(callRecordsQueryParamConfig.getConditionUser());
        }
        if(callRecordsQueryParamConfig.getContiditonType() != null && !callRecordsQueryParamConfig.getContiditonType().isEmpty()){
            callRecordQueryListParam.setContiditonType(callRecordsQueryParamConfig.getContiditonType());
        }
        if(callRecordsQueryParamConfig.getPageSize() != null && !callRecordsQueryParamConfig.getPageSize().isEmpty()){
            callRecordQueryListParam.setPageSize(callRecordsQueryParamConfig.getPageSize());
        }
        if(callRecordsQueryParamConfig.getPageNum() != null && !callRecordsQueryParamConfig.getPageNum().isEmpty()){
            callRecordQueryListParam.setPageNum(callRecordsQueryParamConfig.getPageNum());
        }

        logger.info("callRecordsQueryParamConfig:{}", JSON.toJSONString(callRecordsQueryParamConfig));
        Map<String, String> paramsQueryCallRecord = objectMapper.convertValue(callRecordQueryListParam, Map.class);
        String s = HttpClientUtil.doPost(spiderConfig.getQueryCallRecordAjaxUrl(), paramsQueryCallRecord, closeBroadcastCookies, null);
        // 测试数据
//            String s = getTestData();


        CallRecordResponseDTO queryCallRecordDTO = JSON.parseObject(s, CallRecordResponseDTO.class);

//                logger.info("queryCallRecordDTO:{}", s );
        List<CallRecordResponseDTO.CallRecord> callRecordList = queryCallRecordDTO.getCallRecordList();
        return callRecordList;
    }

    @Override
    public String closeBroadcastAll() {
        try {

            List<CallRecordResponseDTO.CallRecord> startBroadcastCallRecords = getStartBroadcastCallRecords();
            if (startBroadcastCallRecords != null && !startBroadcastCallRecords.isEmpty()) {
                for (int i = 0; i < startBroadcastCallRecords.size(); i++) {
                    CallRecordResponseDTO.CallRecord callRecord = startBroadcastCallRecords.get(i);
                    if (callRecord.getStatus() == 0  // 0:广播进行中 1:已停止
                            && callRecordsQueryParamConfig.getCallerName().equals(callRecord.getCallerName())
                            && callRecordsQueryParamConfig.getAssetName().equals(callRecord.getAssetName())
                            && callRecord.getType() == Integer.parseInt(callRecordsQueryParamConfig.getType())){
                        String callRecordId = String.valueOf(callRecord.getId());
                        stopIssueAudioFile(callRecordId);
                    }
                }
            }
        } catch (Exception e) {
            logger.error("关播异常");
            e.printStackTrace();
            throw new RuntimeException(e);
        }
        return "";
    }

    /**
     *  关播-直播流
     * @param callRecordId
     * @return
     */
    @Override
    public String stopIssueAudioFile(String callRecordId) {

        // 获取关播主页cookie
        Map<String, String> closeBroadcastCookies = closeBroadcastProcessor.getCloseBroadcastCookies();

        String result = "没有广播记录id，关播失败";
        if(callRecordId != null && !callRecordId.isEmpty()){
            try {
                Map<String, String> params = new HashMap<>();
                params.put("callRecordId", callRecordId);
                result = HttpClientUtil.doGet(spiderConfig.getStopIssueAudioFileUrl(), params, closeBroadcastCookies, null);
                // 测试数据
//                result = "{\n" +
//                        "    \"areaListString\": null,\n" +
//                        "    \"assetName\": null,\n" +
//                        "    \"audioFileType\": null,\n" +
//                        "    \"broadCastType\": null,\n" +
//                        "    \"callRecordId\": 223219,\n" +
//                        "    \"errMsg\": null,\n" +
//                        "    \"eventLevel\": null,\n" +
//                        "    \"fileId\": null,\n" +
//                        "    \"issueTerminals\": null,\n" +
//                        "    \"mediaType\": null,\n" +
//                        "    \"resultString\": null,\n" +
//                        "    \"schemeType\": null,\n" +
//                        "    \"volume\": null\n" +
//                        "}";
                logger.info("stopIssueAudioFile关播结果：{}", result);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return result;
    }

    /**
     * 预览直播流关闭
     * @param recordId
     * @return
     */
    @Override
    public String stopListenCallRecord(String recordId) {

        // 获取关播主页cookie
        Map<String, String> closeBroadcastCookies = closeBroadcastProcessor.getCloseBroadcastCookies();

        String result = "";
        if(recordId != null && !recordId.isEmpty()){
            try {
                Map<String, String> params = new HashMap<>();
                params.put("recordId", recordId);
                result = HttpClientUtil.doGet(spiderConfig.getStopListenCallRecordUrl(), params, closeBroadcastCookies, null);
                logger.info("stopListenCallRecord关播结果：{}", result);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return result;
    }
    /**
     * 语音开播
     * @param startCallParamDTO
     * @return
     */
    @Override
    public StartCallDTO startCall(StartCallParamDTO startCallParamDTO) {

        String jsonParam;
        if(startCallParamDTO == null){
            jsonParam = JSON.toJSONString(startCallParamConfig);
        }else {
            if(startCallParamDTO.getAreaList() == null){
                startCallParamDTO.setAreaList(startCallParamConfig.getAreaList());
            }
            if(startCallParamDTO.getIssueTerminals() == null){
                startCallParamDTO.setIssueTerminals(startCallParamConfig.getIssueTerminals());
            }
            if(startCallParamDTO.getBroadCastType() == null){
                startCallParamDTO.setBroadCastType(startCallParamConfig.getBroadCastType());
            }
            if(startCallParamDTO.getMediaType() == null){
                startCallParamDTO.setMediaType(startCallParamConfig.getMediaType());
            }
            if(startCallParamDTO.getSchemeType() == null){
                startCallParamDTO.setSchemeType(startCallParamConfig.getSchemeType());
            }
            if(startCallParamDTO.getIssueVolume() == null){
                startCallParamDTO.setIssueVolume(startCallParamConfig.getIssueVolume());
            }
//            设置时间戳
            if(startCallParamDTO.getRecordTimeCode() == null || startCallParamDTO.getRecordTimeCode().isEmpty()){
                if(startCallParamConfig.getRecordTimeCode() == null || startCallParamConfig.getRecordTimeCode().isEmpty()){
                    startCallParamDTO.setRecordTimeCode(String.valueOf(new Date().getTime()));
                }else {
                    startCallParamDTO.setRecordTimeCode(startCallParamConfig.getRecordTimeCode());
                }
            }
            if(startCallParamDTO.getEventLevel() == null){
                startCallParamDTO.setEventLevel(startCallParamConfig.getEventLevel());
            }
            if(startCallParamDTO.getRdsSendMode() == null){
                startCallParamDTO.setRdsSendMode(startCallParamConfig.getRdsSendMode());
            }
            jsonParam = JSON.toJSONString(startCallParamDTO);
        }
        //获取开播 Cookie
        Map<String, String> startBroadcastCookies = startBroadcastProcessor.getStartBroadcastCookies();
        try {
            Map<String, String> paramMap = objectMapper.readValue(jsonParam, Map.class);
            String result = HttpClientUtil.doPost(spiderConfig.getStartCallUrl(), paramMap, startBroadcastCookies, null);
            logger.info("开语音广播结果：{}", result);
            StartCallDTO startCallDTO = JSON.parseObject(result, StartCallDTO.class);
            if(startCallDTO != null){
                String resultString = startCallDTO.getResultString();
                if(startCallDTO.getErrMsg() == null || startCallDTO.getErrMsg().isEmpty()){
                    if ("startCut".equals(startCallDTO.getResultString())) {
                        if("2".equals(startCallDTO.getSchemeType())){
                            //RDS
                            resultString = "存在更高级别的广播";
                        }else{
                            resultString = "下发成功，存在更高级别的广播";
                        }
                    } else if("chnlError".equals(startCallDTO.getResultString())){
                        resultString = "下发成功，无空闲下发通道";
                    } else{
                        resultString = "下发成功，指令已下发，请讲话";
                    }
                    logger.info("开语音广播结果：{}", resultString);
                }else{
                    logger.info("开语音广播结果：{}", startCallDTO.getErrMsg());
                }
                logger.info("开语音广播CallId：{}", startCallDTO.getCallId());
                ebSpeakerCallIdList.add(startCallDTO.getCallId());
                startCallDTO.setResultString(resultString);
                return startCallDTO;
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return null;
    }
    /**
     * 语音关播
     * @param callId
     * @return
     */
    @Override
    public String stopCall(String callId) {
        // 获取关播主页cookie
        Map<String, String> closeBroadcastCookies = closeBroadcastProcessor.getCloseBroadcastCookies();
        ebSpeakerCallIdList.stream().iterator().forEachRemaining(ebSpeakerCallId -> {
            try {
                Map<String, String> params = new HashMap<>();
                params.put("callId", ebSpeakerCallId);
                String result = HttpClientUtil.doGet(spiderConfig.getStopCallUrl(), null, closeBroadcastCookies, null);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        });
        ebSpeakerCallIdList.clear();

        return "ok";
    }

    public boolean checkAreaCode(String areaCodeList, List<CallRecordResponseDTO.TargetArea> targetAreaList) {
        if (areaCodeList == null || areaCodeList.isEmpty()) {
            return false;
        }
        String[] split = areaCodeList.split(",");
        if (targetAreaList == null || targetAreaList.isEmpty()) {
            return false;
        }
        // 循环判断 每个区域码 全匹配
        for (int i = 0; i < split.length; i++) {
            boolean result = false;
            for (int j = 0; j < targetAreaList.size(); j++) {
                if (split[i].equals(targetAreaList.get(j).getDivisionCode())) {
                    result = true;
                }
            }
            if (!result) {
                return false;
            }
        }
        return true;
    }

    private String getJsonParamString(IssueLiveStreamParamDTO issueLiveStreamParamDTO) {
        String jsonParamString;
        if(issueLiveStreamParamDTO == null){
            jsonParamString = JSON.toJSONString(issueLiveStreamParamConfig);
        }else {
            if(issueLiveStreamParamDTO.getFileId() == null){
                issueLiveStreamParamDTO.setFileId(issueLiveStreamParamConfig.getFileId());
            }
            if(issueLiveStreamParamDTO.getProgramId() == null){
                issueLiveStreamParamDTO.setProgramId(issueLiveStreamParamConfig.getProgramId());
            }
            if(issueLiveStreamParamDTO.getAreaListString() == null){
                issueLiveStreamParamDTO.setAreaListString(issueLiveStreamParamConfig.getAreaListString());
            }
            if(issueLiveStreamParamDTO.getIssueTerminals() == null){
                issueLiveStreamParamDTO.setIssueTerminals(issueLiveStreamParamConfig.getIssueTerminals());
            }
            if(issueLiveStreamParamDTO.getBroadCastType() == null){
                issueLiveStreamParamDTO.setBroadCastType(issueLiveStreamParamConfig.getBroadCastType());
            }
            if(issueLiveStreamParamDTO.getMediaType() == null){
                issueLiveStreamParamDTO.setMediaType(issueLiveStreamParamConfig.getMediaType());
            }
            if(issueLiveStreamParamDTO.getSchemeType() == null){
                issueLiveStreamParamDTO.setSchemeType(issueLiveStreamParamConfig.getSchemeType());
            }
            if(issueLiveStreamParamDTO.getVolume() == null){
                issueLiveStreamParamDTO.setVolume(issueLiveStreamParamConfig.getVolume());
            }
            if(issueLiveStreamParamDTO.getEventLevel() == null){
                issueLiveStreamParamDTO.setEventLevel(issueLiveStreamParamConfig.getEventLevel());
            }
            if(issueLiveStreamParamDTO.getAssetName() == null){
                issueLiveStreamParamDTO.setAssetName(issueLiveStreamParamConfig.getAssetName());
            }
            if(issueLiveStreamParamDTO.getRdsSendMode() == null){
                issueLiveStreamParamDTO.setRdsSendMode(issueLiveStreamParamConfig.getRdsSendMode());
            }
            jsonParamString  = JSON.toJSONString(issueLiveStreamParamDTO);
        }
        return jsonParamString;
    }

    private static String getTestData() {
        String s = "{\n" +
                "    \"callRecordList\": [\n" +
                "        {\n" +
                "            \"aioFileName\": null,\n" +
                "            \"aioFilesFtpPath\": null,\n" +
                "            \"assetName\": \"中央广播(udp://@192.168.19.182:35001)\",\n" +
                "            \"broadcastType\": 0,\n" +
                "            \"callerDivisionCode\": \"5105030000\",\n" +
                "            \"callerName\": \"杨智强\",\n" +
                "            \"childRecordList\": [\n" +
                "                {\n" +
                "                    \"assetTaskId\": \"735\",\n" +
                "                    \"deviceIndentify\": null,\n" +
                "                    \"deviceRecordDownLoadNum\": null,\n" +
                "                    \"deviceRecordPktsSum\": null,\n" +
                "                    \"downloadStatus\": null,\n" +
                "                    \"id\": 170133,\n" +
                "                    \"multiplexerPortId\": 7,\n" +
                "                    \"platTaskId\": null,\n" +
                "                    \"rdsCmdChannelIds\": null,\n" +
                "                    \"rdsCmdDataChannelIds\": null,\n" +
                "                    \"rdsSessionId\": null,\n" +
                "                    \"schemeType\": 0\n" +
                "                }\n" +
                "            ],\n" +
                "            \"duration\": null,\n" +
                "            \"fileType\": \"AUDIO\",\n" +
                "            \"id\": 223207,\n" +
                "            \"issueDivisionList\": [\n" +
                "                {\n" +
                "                    \"divisionCode\": \"5105030000\",\n" +
                "                    \"divisionLevel\": 4,\n" +
                "                    \"divisionName\": \"上坝社区居民委员会\",\n" +
                "                    \"divisionState\": null,\n" +
                "                    \"fullName\": \"四川 泸州市 纳溪区 安富街道 上坝社区居民委员会\",\n" +
                "                    \"id\": 572801,\n" +
                "                    \"latitude\": \"\",\n" +
                "                    \"longitude\": \"\",\n" +
                "                    \"parentCode\": \"5105030100\"\n" +
                "                }\n" +
                "            ],\n" +
                "            \"issueTerminalList\": null,\n" +
                "            \"startTime\": \"2025/06/10 17:14:58\",\n" +
                "            \"status\": 0,\n" +
                "            \"targetAreaList\": [\n" +
                "                {\n" +
                "                    \"divisionCode\": \"5105030000\",\n" +
                "                    \"divisionId\": 572801,\n" +
                "                    \"divisionLevel\": 4,\n" +
                "                    \"divisionName\": \"上坝街居民委员会\",\n" +
                "                    \"fullName\": \"四川 泸州市 纳溪区 安富街道 上坝街居民委员会\",\n" +
                "                    \"id\": 89,\n" +
                "                    \"parentCode\": \"5105030100\",\n" +
                "                    \"stbName\": null,\n" +
                "                    \"terminalId\": null\n" +
                "                }\n" +
                "            ],\n" +
                "            \"targetTerminalList\": null,\n" +
                "            \"termDivisionString\": null,\n" +
                "            \"type\": 17\n" +
                "        }\n" +
                "    ],\n" +
                "    \"conditionStartTime\": \"\",\n" +
                "    \"conditionUser\": \"\",\n" +
                "    \"contiditonType\": -1,\n" +
                "    \"deviceIndentify\": \"\",\n" +
                "    \"errMsg\": null,\n" +
                "    \"resultTotalCount\": null,\n" +
                "    \"writeLogFlag\": 0\n" +
                "}";
        return s;
    }

}
